package Exercise;

import java.util.concurrent.locks.LockSupport;

public class Two {
    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                System.out.println("running-before..." + System.currentTimeMillis());
                try {
                    // ②睡眠2s,线程执行权回到main线程
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("park之前: " + System.currentTimeMillis());
                // ④暂停当前线程(无效,因为之前预处理过一次unpark)
                LockSupport.park();
                System.out.println("park之前: " + System.currentTimeMillis());
                System.out.println("running-after..." + System.currentTimeMillis());
            }
        };

        t1.start();

        // ①确保t1线程先执行
        Thread.sleep(10);

        // ③解除t1线程的暂停(相当于预处理一次unpark)
        LockSupport.unpark(t1);
        System.out.println(t1.isInterrupted());
    }


}
